<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>${sysName}</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="${resRoot}/layui/css/layui.css" media="all" />
  <link rel="stylesheet" href="${resRoot}/layui/admin/admin.css" media="all" />
	<link id="layuicss-layer" rel="stylesheet" href="${resRoot}/layui/css/modules/layer/default/layer.css" media="all">
	<script type="text/javascript" src="${resRoot}/ckeditor/ckeditor.js"></script>
	<script type="text/javascript" src="${resRoot}/ckfinder/ckfinder.js"></script>
</head>
<body>
<div class="layui-fluid">   
          <div class="layui-card">
          <div class="layui-form layui-card-header layuiadmin-card-header-auto"> 
 
<form class="layui-form" action="#" style="margin-top: 20px;" >
<input type="hidden" id="id" value="<#if memberCardDTO??>${ memberCardDTO.id}<#else></#if>" >
  <div class="layui-form-item">
    <label class="layui-form-label">商户id</label>
    <div class="layui-input-inline">
	      <input type="text" name="bussinessId" id="bussinessId" value="<#if memberCardDTO?? && memberCardDTO.bussinessId?? > ${ memberCardDTO.bussinessId! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入商户id" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入商户id</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">卡号</label>
    <div class="layui-input-inline">
	      <input type="text" name="cardNo" id="cardNo" value="<#if memberCardDTO?? && memberCardDTO.cardNo?? > ${ memberCardDTO.cardNo! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入卡号" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入卡号</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">会员id</label>
    <div class="layui-input-inline">
	      <input type="text" name="memberId" id="memberId" value="<#if memberCardDTO?? && memberCardDTO.memberId?? > ${ memberCardDTO.memberId! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入会员id" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入会员id</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">姓名</label>
    <div class="layui-input-inline">
	      <input type="text" name="name" id="name" value="<#if memberCardDTO?? && memberCardDTO.name?? > ${ memberCardDTO.name! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入姓名" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入姓名</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">性别</label>
    <div class="layui-input-inline">
	      <input type="text" name="sex" id="sex" value="<#if memberCardDTO?? && memberCardDTO.sex?? > ${ memberCardDTO.sex! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入性别" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入性别</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">生日</label>
    <div class="layui-input-inline">
	      <input type="text" name="birthday" id="birthday" value="<#if memberCardDTO?? && memberCardDTO.birthday?? > ${ memberCardDTO.birthday! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入生日" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入生日</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">邮箱</label>
    <div class="layui-input-inline">
	      <input type="text" name="email" id="email" value="<#if memberCardDTO?? && memberCardDTO.email?? > ${ memberCardDTO.email! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入邮箱" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入邮箱</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">电话</label>
    <div class="layui-input-inline">
	      <input type="text" name="tel" id="tel" value="<#if memberCardDTO?? && memberCardDTO.tel?? > ${ memberCardDTO.tel! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入电话" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入电话</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">等级</label>
    <div class="layui-input-inline">
	      <input type="text" name="level" id="level" value="<#if memberCardDTO?? && memberCardDTO.level?? > ${ memberCardDTO.level! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入等级" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入等级</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">积分</label>
    <div class="layui-input-inline">
	      <input type="number" name="point" id="point" value="<#if memberCardDTO?? && memberCardDTO.point?? > ${ memberCardDTO.point! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入积分" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入积分</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">绑定时间</label>
    <div class="layui-input-inline">
    	<input type="text" class="layui-input" id="bindTime" placeholder="yyyy-MM-dd" value="<#if memberCardDTO?? && memberCardDTO.bindTime?? > ${ memberCardDTO.bindTime?datetime}</#if>" >
	      
    </div>
    <div class="layui-form-mid layui-word-aux">请输入绑定时间</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">来源</label>
    <div class="layui-input-inline">
	      <input type="text" name="source" id="source" value="<#if memberCardDTO?? && memberCardDTO.source?? > ${ memberCardDTO.source! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入来源" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入来源</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">是否绑定</label>
    <div class="layui-input-inline">
	      <input type="text" name="isBind" id="isBind" value="<#if memberCardDTO?? && memberCardDTO.isBind?? > ${ memberCardDTO.isBind! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入是否绑定" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入是否绑定</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">状态</label>
    <div class="layui-input-inline">
	      <input type="text" name="state" id="state" value="<#if memberCardDTO?? && memberCardDTO.state?? > ${ memberCardDTO.state! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入状态" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入状态</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">会员数据</label>
    <div class="layui-input-inline">
	      <input type="text" name="memberData" id="memberData" value="<#if memberCardDTO?? && memberCardDTO.memberData?? > ${ memberCardDTO.memberData! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入会员数据" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入会员数据</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">其他系统id</label>
    <div class="layui-input-inline">
	      <input type="text" name="otherSysId" id="otherSysId" value="<#if memberCardDTO?? && memberCardDTO.otherSysId?? > ${ memberCardDTO.otherSysId! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入其他系统id" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入其他系统id</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">详情</label>
    <div class="layui-input-block">
    <!-- 
  	<textarea class="layui-textarea layui-hide content" name="content"  id="intro"><#if memberCardDTO?? && memberCardDTO.intro?? > ${ memberCardDTO.intro! }</#if></textarea>
     -->
  	<textarea name="editor1" id="intro" rows="20" cols="2"><#if memberCardDTO?? && memberCardDTO.intro?? > ${ memberCardDTO.intro! }</#if></textarea>
    </div>
  </div>
  
  <!-- 图片 -->
  	<div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">头像</label>
      <div class="layui-input-inline">
      <div class="site-demo-upload">
		  <img id="headPicUrl_img" imgName="<#if memberCardDTO?? && memberCardDTO.headPicUrl?? > ${ memberCardDTO.headPicUrl! }</#if>" src="<#if memberCardDTO?? && memberCardDTO.headPicUrl?? > ${ memberCardDTO.headPicUrl! }</#if>" style="max-width:200px;max-height:200px;">
		  <button type="button" class="layui-btn" id="test17">
		  <i class="layui-icon"></i>上传头像
		</button><input class="layui-upload-file" type="file" accept="images" name="fileField" id="fileField">
		</div>
      </div>
    </div>
  </div>
  

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" id="submitBtn"  lay-submit=""  type="button">立即提交</button>
      <button type="button" class="layui-btn layui-btn-primary" onclick="backList();" >返回</button>
    </div>
  </div>
</form>
</div>
  </div>
  </div>
<script src="${resRoot}/layui/layui.js" charset="utf-8"></script>
<script src="${resRoot}/js/jquery.min.js?v=2.1.4"></script>
<script type="text/javascript" src="${resRoot}/js/ajaxfileupload.js"></script>
<script>
function backList() {
	layer.closeAll("iframe");
    //刷新父页面
    parent.location.reload();
}

function removeImg(id) {
	layer.confirm('您是确认删除/查看该图片吗？', {
		  btn: ['确认','查看'] //按钮
		}, function(){
			$("#" + id).attr("src", "");
			layer.msg('已删除！');
		}, function(){
			window.open($("#" + id).attr("src"));
		  //layer.msg('已取消！');
		});
}
layui.use(['form', 'layedit', 'laydate', 'upload'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
  
  var upload = layui.upload;
  laydate.render({
	    elem: '#bindTime'
	    ,type: 'datetime'
	  });

		//创建一个编辑器
		  /* layedit.sync(introeditIndex);
		  var introeditIndex = layedit.build('intro',{
		      height : 535,
		      uploadImage : {
		          url : "${base}/textUploadImage"
		      }
		  }); */
		  
		  var intro = CKEDITOR.replace( 'intro' );
		    CKFinder.setupCKEditor(intro, '${base}/ckfinder/');
		var uploadInst17 = upload.render({
		    elem: '#test17' //绑定元素
		    ,url: '${base}/uploadImage' //上传接口
		    ,done: function(res){
		    if(res != "") {
	    		var obj = res;
				$("#headPicUrl_img").attr("src", '${base}' + obj.imageUrl);
				$("#headPicUrl_img").attr("imgName", obj.imageUrl);
	    		
			}
		      //上传完毕回调
		    }
		    ,error: function(){
		      //请求异常回调
		    }
		  });

  
  
	
  
  //自定义验证规则
  form.verify({
    title: function(value){
      if(value.length == 0){
        return '参数不能为空';
      }
    }
    ,pass: [/(.+){6,12}$/, '密码必须6到12位']
    ,content: function(value){
      layedit.sync(editIndex);
    }
  });
  
  
  
  $("#submitBtn").click(function(){
		var bussinessId=$("#bussinessId").val();
		var cardNo=$("#cardNo").val();
		var memberId=$("#memberId").val();
		var name=$("#name").val();
		var sex=$("#sex").val();
		var birthday=$("#birthday").val();
		var email=$("#email").val();
		var tel=$("#tel").val();
		var level=$("#level").val();
		var point=$("#point").val();
		var bindTime=$("#bindTime").val();
		var source=$("#source").val();
		var isBind=$("#isBind").val();
		var state=$("#state").val();
		var memberData=$("#memberData").val();
		var otherSysId=$("#otherSysId").val();
	  // var intro= layedit.getContent(introeditIndex);
	  var intro=$("#intro").val();
	  var headPicUrl=$("#headPicUrl_img").attr("imgName");
		var flag = true;
		if(bussinessId=="" || bussinessId ==null || bussinessId =="undefined") {
			layer.alert("请输入商户id！");
		      flag = false;
		      return false;
		}
		if(cardNo=="" || cardNo ==null || cardNo =="undefined") {
			layer.alert("请输入卡号！");
		      flag = false;
		      return false;
		}
		if(memberId=="" || memberId ==null || memberId =="undefined") {
			layer.alert("请输入会员id！");
		      flag = false;
		      return false;
		}
		if(name=="" || name ==null || name =="undefined") {
			layer.alert("请输入姓名！");
		      flag = false;
		      return false;
		}
		if(sex=="" || sex ==null || sex =="undefined") {
			layer.alert("请输入性别！");
		      flag = false;
		      return false;
		}
		if(birthday=="" || birthday ==null || birthday =="undefined") {
			layer.alert("请输入生日！");
		      flag = false;
		      return false;
		}
		if(email=="" || email ==null || email =="undefined") {
			layer.alert("请输入邮箱！");
		      flag = false;
		      return false;
		}
		if(tel=="" || tel ==null || tel =="undefined") {
			layer.alert("请输入电话！");
		      flag = false;
		      return false;
		}
		if(level=="" || level ==null || level =="undefined") {
			layer.alert("请输入等级！");
		      flag = false;
		      return false;
		}
		if(point=="" || point ==null || point =="undefined") {
			layer.alert("请输入积分！");
		      flag = false;
		      return false;
		}
		if(bindTime=="" || bindTime ==null || bindTime =="undefined") {
			layer.alert("请输入绑定时间！");
		      flag = false;
		      return false;
		}
		if(source=="" || source ==null || source =="undefined") {
			layer.alert("请输入来源！");
		      flag = false;
		      return false;
		}
		if(isBind=="" || isBind ==null || isBind =="undefined") {
			layer.alert("请输入是否绑定！");
		      flag = false;
		      return false;
		}
		if(state=="" || state ==null || state =="undefined") {
			layer.alert("请输入状态！");
		      flag = false;
		      return false;
		}
		if(memberData=="" || memberData ==null || memberData =="undefined") {
			layer.alert("请输入会员数据！");
		      flag = false;
		      return false;
		}
		if(otherSysId=="" || otherSysId ==null || otherSysId =="undefined") {
			layer.alert("请输入其他系统id！");
		      flag = false;
		      return false;
		}
		if(intro=="" || intro ==null || intro =="undefined") {
			layer.alert("请输入详情！");
		      flag = false;
		      return false;
		}
		if(headPicUrl=="" || headPicUrl ==null || headPicUrl =="undefined") {
			layer.alert("请输入头像！");
		      flag = false;
		      return false;
		}
		if(flag) {
			$.ajax({
				type : "post",
				url : "${base}/sys/memberCardDTO/save",
				data : {
					bussinessId : bussinessId,
					cardNo : cardNo,
					memberId : memberId,
					name : name,
					sex : sex,
					birthday : birthday,
					email : email,
					tel : tel,
					level : level,
					point : point,
					bindTime : bindTime,
					source : source,
					isBind : isBind,
					state : state,
					memberData : memberData,
					otherSysId : otherSysId,
					intro : intro,
					headPicUrl : headPicUrl,
					id : id					
					},
				dataType : "json",
				async : false,
				success : function(data) {
					if(data.message == 2) {
							layer.msg('请完善数据！');   
						} else if(data.message == 1) {
							layer.msg('保存成功！', {
							  icon: 1,
							  time: 2000 //2秒关闭（如果不配置，默认是3秒）
							}, function(){
								backList();
							});   
						} else {
							layer.msg('系统繁忙！'); 
						}
				}
			}); 
		}
	});
  
  
});

layui.use('upload', function(){
	  
});  
</script>
</body>
</html>